package com.ds.list.stack;

import java.util.List;
import java.util.Random;

import org.junit.Test;

import com.ds.tree.AvlTree;
import com.ds.tree.BinaryTree;

public class Test2 {

	@Test
	public void test() {

		String regex = "[+\\-*/()]+";

		String[] list = "1+(2-3)*4/5".split(regex);

		for (String s : list) {
			System.out.println(s);
		}

	}

	@Test
	public void test2() {
		Random rand = new Random();
		BinaryTree<Integer> tree = new BinaryTree<Integer>();
		for (int i = 0; i < 100; i++) {

			int value = rand.nextInt(100);
			System.out.print(value + " ");
			tree.addNode(value);
		}
		System.out.println();

		List<Integer> ls = tree.getAll();
		System.out.println("size : " + ls.size() + " " + ls);
		tree.showTree();
		int max = tree.getMax();
		System.out.println("delete " + max);
		tree.delete(max);
		
		for (int i = 0; i < 10; i++) {
			int value = rand.nextInt(100);
			System.out.println("delete " + value);
			tree.delete(value);
		}
		
		int min = tree.getMin();
		System.out.println("delete " + min);
		tree.delete(min);
		
		ls = tree.getAll();
		System.out.println("size : " + ls.size() + " " + ls);
		tree.showTree();
		
		
	}
	
	@Test
	public void test3() {
		
		Random rand = new Random();
		BinaryTree<Integer> tree1 = new BinaryTree<Integer>();
		AvlTree<Integer> tree2 = new AvlTree<Integer>();
		for (int i = 0; i < 100; i++) {

			int value = rand.nextInt(100);
			System.out.println(value + " ");
			tree1.addNode(value);
			tree2.insert(value);
		}
		System.out.println();
		
		tree1.showTree();
		tree2.showTree();
	}
	
	@Test
	public void test4() {
		
		AvlTree<Integer> tree = new AvlTree<Integer>();
		
		tree.insert(4);
		tree.insert(2);
		tree.insert(5);
		tree.insert(3);
		tree.showTree();
		tree.remove(5);
		tree.showTree();
		
	}
	
	@Test
	public void test5() {
		
		AvlTree<Integer> tree = new AvlTree<Integer>();
		
		tree.insert(16);
		tree.insert(8);
		tree.insert(18);
		tree.insert(4);
		tree.insert(12);
		tree.insert(17);
		tree.insert(20);
		tree.insert(2);
		tree.insert(6);
		tree.insert(10);
		tree.insert(14);
		tree.insert(19);
		tree.insert(1);
		tree.insert(3);
		tree.insert(5);
		tree.insert(7);
		tree.insert(9);
		tree.insert(11);
		tree.insert(13);
		tree.insert(15);
		tree.showTree();
		tree.remove(18);
		tree.showTree();
		
	}
}
